package com.masterrabbit.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.masterrabbit.common.log.annotation.Log;
import com.masterrabbit.common.log.enums.BusinessType;
import com.masterrabbit.common.security.annotation.RequiresPermissions;
import com.masterrabbit.domain.Merchants;
import com.masterrabbit.service.IMerchantsService;
import com.masterrabbit.common.core.web.controller.BaseController;
import com.masterrabbit.common.core.web.domain.AjaxResult;
import com.masterrabbit.common.core.utils.poi.ExcelUtil;
import com.masterrabbit.common.core.web.page.TableDataInfo;

/**
 * 商户信息Controller
 * 
 * @author laotu
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/merchants")
public class MerchantsController extends BaseController
{
    @Autowired
    private IMerchantsService merchantsService;

    /**
     * 查询商户信息列表
     */
    @RequiresPermissions("masterrabbit-kaixuan:merchants:list")
    @GetMapping("/list")
    public TableDataInfo list(Merchants merchants)
    {
        startPage();
        List<Merchants> list = merchantsService.selectMerchantsList(merchants);
        return getDataTable(list);
    }

    /**
     * 导出商户信息列表
     */
    @RequiresPermissions("masterrabbit-kaixuan:merchants:export")
    @Log(title = "商户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Merchants merchants)
    {
        List<Merchants> list = merchantsService.selectMerchantsList(merchants);
        ExcelUtil<Merchants> util = new ExcelUtil<Merchants>(Merchants.class);
        util.exportExcel(response, list, "商户信息数据");
    }

    /**
     * 获取商户信息详细信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:merchants:query")
    @GetMapping(value = "/{merchantId}")
    public AjaxResult getInfo(@PathVariable("merchantId") Long merchantId)
    {
        return success(merchantsService.selectMerchantsByMerchantId(merchantId));
    }

    /**
     * 新增商户信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:merchants:add")
    @Log(title = "商户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Merchants merchants)
    {
        return toAjax(merchantsService.insertMerchants(merchants));
    }

    /**
     * 修改商户信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:merchants:edit")
    @Log(title = "商户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Merchants merchants)
    {
        return toAjax(merchantsService.updateMerchants(merchants));
    }

    /**
     * 删除商户信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:merchants:remove")
    @Log(title = "商户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{merchantIds}")
    public AjaxResult remove(@PathVariable Long[] merchantIds)
    {
        return toAjax(merchantsService.deleteMerchantsByMerchantIds(merchantIds));
    }
}
